package com.kevin.data;

import com.google.common.base.CharMatcher;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.util.concurrent.*;
import lombok.val;
import lombok.var;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.expression.operators.conditional.AndExpression;
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import net.sf.jsqlparser.expression.operators.relational.InExpression;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.statement.select.SelectBody;
import net.sf.jsqlparser.statement.select.WithItem;
import sun.tools.tree.EqualExpression;
import sun.tools.tree.StringExpression;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.*;

/**
 * @author Kevin Liu
 * @date 2020/10/12 4:25 下午
 */
public class JsqlParse {



    public static void  jsplParseTest() throws JSQLParserException {
        String sql = "select * from user where id = 1";
        Statement statement = CCJSqlParserUtil.parse(sql);
        Select select = (Select)statement;
        final SelectBody selectBody = select.getSelectBody();
        final PlainSelect plainSelect = (PlainSelect) selectBody;
        System.out.println(plainSelect.getFromItem());
        var where = plainSelect.getWhere();
        EqualsTo equalsTo = new EqualsTo();
        Column username = new Column("username");
        equalsTo.setLeftExpression(username);
        StringValue stringValue = new StringValue("kevin");
        equalsTo.setRightExpression(stringValue);
        where = new AndExpression(where,equalsTo);
        plainSelect.setWhere(where);
        System.out.println(plainSelect.toString());
    }
    public static void main(String[] args) throws JSQLParserException {
        jsplParseTest();
    }
}

